;
; vmchk.asm
;

include vmbdoor.inc

; enable x486 instructions, but use 16 bit segment
.486
option segment:use16

; code segment
codes	segment para use16 public 'CODE'
codes	ends

; data segment
datas	segment byte use16 public 'DATA'
BDOOR_MAGIC	dword  	VMWARE_MAGIC
BDOOR_PORT  	word	VMWARE_PORT
MSG_VMNG	byte	'Not running inside VMware.', CR, LF, '$'
MSG_VMVER1	byte	'Running inside VMware (version '
MSG_VMVER2	byte	?
MSG_VMVER3	byte	').', LF, CR, '$'
OPTION_SILENT	byte	0
datas	ends

main	group codes,datas

codes	segment
; for tiny memory model (.com), all seg is the same
assume	cs:main,ds:main,es:main,ss:main
org	100h
entry:
	; Get VMware version
        mov 	eax, [BDOOR_MAGIC]
        mov 	dx, [BDOOR_PORT]
	xor 	ecx,ecx
	mov 	cl, VMCMD_GET_VERSION	; get version command
        in 	eax, dx

	; Check Magic number
	cmp	ebx,[BDOOR_MAGIC]
	jne	not_in_vm

	; Inside VM
	mov 	bl, al			; store version number
	add	al,30h			; convert version to a digit
	mov	[MSG_VMVER2],al
	mov 	dx, offset MSG_VMVER1	; vm version message
	jmp	print_msg

not_in_vm:
	xor	bl, bl			; version = 0
	mov	dx, offset MSG_VMNG	; not in VM message

print_msg:
	mov 	ah, 09h			; String output function
	int	21h

terminate:
	; Now Return to DOS
	mov	al, bl			; restore version number
	mov	ah, 4ch			; exit to dos function
	int	21h

codes	ends
end	entry
; end of file
